
import { Body, Query, Controller, Get, Post, Req, Res, Param, Module, Put, Delete } from '@nestjs/common';
import { DictionaryService } from './dictionary.service';
import { UseGuards } from '@nestjs/common'
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
@Controller('dictionaries')
export class DictionaryController {
    constructor(private readonly dictionaryService: DictionaryService) { }

    @Post('create')
    @UseGuards(JwtAuthGuard)
    createDictionary(@Body() body: { type: string; name: string, description: string }) {
        return this.dictionaryService.createDictionary(body.type, body.name, body.description);
    }
    @Put(':type')
    @UseGuards(JwtAuthGuard)
    updateDictionary(
        @Param('type') type: string,
        @Body() body: { newName: string }
    ) {
        return this.dictionaryService.updateDictionary(type, body.newName);
    }
    @Post(':type/items')
    @UseGuards(JwtAuthGuard)
    addDictionaryItem(
        @Param('type') type: string,
        @Body() body: { key: string; value: string }
    ) {
        return this.dictionaryService.addDictionaryItem(type, body.key, body.value);
    }
    @Put('items/:id')
    @UseGuards(JwtAuthGuard)
    updateDictionaryItem(
        @Param('id') id: string,
        @Body() body: { newKey: string; newValue: string }
    ) {
        return this.dictionaryService.updateDictionaryItem(
            Number(id),
            body.newKey,
            body.newValue
        );
    }
    @Delete('items/:id')
    @UseGuards(JwtAuthGuard)
    removeDictionaryItem(@Param('id') id: string) {
        return this.dictionaryService.removeDictionaryItem(Number(id));
    }

    @Delete(':type')
    @UseGuards(JwtAuthGuard)
    async deleteDictionary(@Param('type') type: string) {
        return this.dictionaryService.deleteDictionary(type);
    }

    @Get('ByType/:type')
    @UseGuards(JwtAuthGuard)
    getByType(@Param('type') type: string) {
        return this.dictionaryService.getDictionaryByType(type);
    }

    @Get('All/:type')
    @UseGuards(JwtAuthGuard)
    getAllDictionaries(@Param('type') type: string) {
        return this.dictionaryService.getAllDictionaries(type);
    }
}
